<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    width="600px"
    :close-on-click-modal="false"
    :modal-append-to-body="false"
    :append-to-body="true"
    :before-close="handleClose"
  >
    <el-form label-width="120px">
      <el-form-item label="布局类型">
        <el-radio-group v-model="layoutType">
          <el-radio :label="6">
            <el-image src="/image/leftTop.png" />
          </el-radio>
          <el-radio :label="4">
            <el-image src="/image/top.png" />
          </el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer" style="text-align: center">
      <el-button type="primary" @click="save">保存</el-button>
      <el-button @click="reset">重置</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { SetLayoutType } from '@/customForm/api/form'
export default {
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    formId: {
      type: String,
      default: null
    },
    formName: {
      type: String,
      default: null
    },
    value: {
      type: Number,
      default: 14
    }
  },
  data() {
    return {
      title: '新增表单组',
      layoutType: 14
    }
  },
  watch: {
    visible: {
      handler(val) {
        if (val) {
          this.reset()
        }
      },
      immediate: true
    },
    value: {
      handler(val) {
        if (val) {
          this.layoutType = val
        }
      },
      immediate: false
    }
  },
  mounted() {},
  methods: {
    async reset() {
      this.title = this.formName + '搜索栏布局方式'
    },
    handleClose() {
      this.$emit('update:visible', false)
    },
    async save() {
      await SetLayoutType(this.formId, this.layoutType)
      this.$message({
        type: 'success',
        message: '保存成功!'
      })
      this.$emit('input', this.layoutType)
      this.$emit('update:visible', false)
      this.$emit('save', this.layoutType)
    }
  }
}
</script>
